# -*- coding: utf-8 -*-

import pandas as pd
import numpy as np
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import accuracy_score

# 读取数据
train = pd.read_csv("data/train.csv")
test = pd.read_csv("data/test.csv")
submit = pd.read_csv("data/gender_submission.csv")
y_true = submit['Survived']

# 删除无效信息，将有效信息数字化
# Cabin = set(dict(train['Cabin']).values())
Embarked = set(dict(train['Embarked']).values())

train.drop('PassengerId', axis=1, inplace=True)
train.drop('Name', axis=1, inplace=True)
train.drop('Ticket', axis=1, inplace=True)
train.drop('Cabin', axis=1, inplace=True)

train['Sex'] = train['Sex'].replace(['male','female'],[0,1]) 
# train['Cabin'] = train['Cabin'].replace(Cabin, range(len(Cabin)))
train['Embarked'] = train['Embarked'].replace(Embarked, range(len(Embarked)))

for i in range(len(train['Fare'])):
	if train['Fare'][i] < 50:
		train['Fare'][i] = 0
	elif train['Fare'][i] < 100:
		train['Fare'][i] = 1
	elif train['Fare'][i] < 200:
		train['Fare'][i] = 2
	else:
		train['Fare'][i] = 3

for i in range(len(train['Age'])):
	if train['Age'][i] < 18:
		train['Age'][i] = 1
	elif train['Age'][i] < 45:
		train['Age'][i] = 2
	else:
		train['Age'][i] = 0


# print(train['Age'])
# print(train)


test.drop('PassengerId', axis=1, inplace=True)
test.drop('Ticket', axis=1, inplace=True)
test.drop('Name', axis=1, inplace=True)
test.drop('Cabin', axis=1, inplace=True)

test['Sex']=test['Sex'].replace(['male','female'],[0,1]) 
# test['Cabin'] = test['Cabin'].replace(Cabin, range(len(Cabin)))
test['Embarked'] = test['Embarked'].replace(Embarked, range(len(Embarked)))


for i in range(len(test['Fare'])):
	if test['Fare'][i] < 50:
		test['Fare'][i] = 0
	elif test['Fare'][i] < 100:
		test['Fare'][i] = 1
	elif test['Fare'][i] < 200:
		test['Fare'][i] = 2
	else:
		test['Fare'][i] = 3

for i in range(len(test['Age'])):
	if test['Age'][i] < 18:
		test['Age'][i] = 1
	elif test['Age'][i] < 45:
		test['Age'][i] = 2
	else:
		test['Age'][i] = 0


# 取出训练集的y
y_train = train.pop('Survived')


# 建立LASSO逻辑回归模型
clf = MLPClassifier()
clf.fit(train, y_train)
y_pred = clf.predict(test)

# output the accuracy
print('accuracy:', accuracy_score(y_true, y_pred))

